home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML Instance.sea / XML Instance / Required / plugins / HTMLWindow.jar / horst / BodyView.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-03-18  |  3.9 KB  |  107 lines

  1. package horst;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.Image;
  6. import java.awt.Rectangle;
  7. import java.awt.Shape;
  8. import java.awt.Toolkit;
  9. import java.awt.image.ImageObserver;
  10. import java.net.URL;
  11.  
  12. public class BodyView extends BlockView implements ImageObserver {
  13.    Image m_bkgImage;
  14.    Color m_bkgColor;
  15.  
  16.    public BodyView(View parent, Element e, HTMLPane container) {
  17.       super(parent, e, container);
  18.    }
  19.  
  20.    public boolean imageUpdate(Image img, int flags, int x, int y, int width, int height) {
  21.       if (this.m_bkgImage == null) {
  22.          return false;
  23.       } else if ((flags & 192) != 0) {
  24.          this.m_bkgImage = null;
  25.          return false;
  26.       } else {
  27.          if ((flags & 48) != 0) {
  28.             super.m_container.repaint((long)super.m_bounds.x);
  29.          }
  30.  
  31.          return true;
  32.       }
  33.    }
  34.  
  35.    protected void init() {
  36.       URL u = Utilities.setURLProperty(super.m_elem.getDocument().getBaseURL(), "background", super.m_elem.getAttributes());
  37.       if (u != null) {
  38.          this.m_bkgImage = Toolkit.getDefaultToolkit().getImage(u);
  39.          if (this.m_bkgImage != null) {
  40.             Toolkit.getDefaultToolkit().prepareImage(this.m_bkgImage, -1, -1, this);
  41.          }
  42.       }
  43.  
  44.       this.m_bkgColor = Utilities.setColorProperty((Color)null, "bgcolor", super.m_elem.getAttributes());
  45.       ((View)this).setInsets(super.m_container.m_props.m_marginHeight, super.m_container.m_props.m_marginWidth, super.m_container.m_props.m_marginHeight, super.m_container.m_props.m_marginWidth);
  46.    }
  47.  
  48.    protected boolean isFloaterClearer() {
  49.       return true;
  50.    }
  51.  
  52.    protected boolean isWrappable() {
  53.       return true;
  54.    }
  55.  
  56.    protected void makeChildren(ViewFactory factory) {
  57.       super.makeChildren(factory);
  58.       if (super.m_children.length > 0 && super.m_children[0] instanceof FrameSetView) {
  59.          ((View)this).setInsets(0, 0, 0, 0);
  60.       }
  61.  
  62.    }
  63.  
  64.    public void paint(Graphics g, Shape alloc) {
  65.       if (super.m_bounds.intersects(alloc.getBounds())) {
  66.          Rectangle allocation = alloc.getBounds();
  67.          int screenWidth = Math.max(allocation.width, super.m_bounds.width + super.m_insets.left + super.m_insets.right);
  68.          int screenHeight = Math.max(allocation.height, super.m_bounds.height + super.m_insets.top + super.m_insets.bottom);
  69.          if (this.m_bkgColor != null) {
  70.             g.setColor(this.m_bkgColor);
  71.             g.fillRect(super.m_bounds.x, super.m_bounds.y, screenWidth, screenHeight);
  72.          }
  73.  
  74.          if (this.m_bkgImage != null && super.m_container.m_props.m_bDisplayBackgroundImage) {
  75.             int w = this.m_bkgImage.getWidth((ImageObserver)null);
  76.             int h = this.m_bkgImage.getHeight((ImageObserver)null);
  77.             int nCols = 1;
  78.             int nRows = 1;
  79.             if (screenWidth > w) {
  80.                nCols = screenWidth / w;
  81.                double rem = (double)screenWidth / (double)w - (double)nCols;
  82.                if (rem > (double)0.0F) {
  83.                   ++nCols;
  84.                }
  85.             }
  86.  
  87.             if (screenHeight > h) {
  88.                nRows = screenHeight / h;
  89.                double rem = (double)screenHeight / (double)h - (double)nRows;
  90.                if (rem > (double)0.0F) {
  91.                   ++nRows;
  92.                }
  93.             }
  94.  
  95.             for(int row = 0; row < nRows; ++row) {
  96.                for(int col = 0; col < nCols; ++col) {
  97.                   g.drawImage(this.m_bkgImage, col * w, row * h, w, h, (ImageObserver)null);
  98.                }
  99.             }
  100.          }
  101.  
  102.          super.paint(g, alloc);
  103.       }
  104.  
  105.    }
  106. }
  107.